#! /usr/bin/env python
#coding=utf-8

import uocbase
    
class Uoc(uocbase.UocBase):
    "UOC_delete"
    uoclevel = 'normal'
    def direct_parse(self):
        "直接型命令分析"
        if not self.uocparams:
            return None
        for i in range(len(self.uocparams)):
            did = uocbase.field_validate(self.uocparams[i], 'int')
            if not did:
                self.user.log.writeLog('params format error: %s' % 
                                       (self.uocparams[i]), 'error')
                return None
            self.uocparams[i] = did
        
        # print [['delete', self.uocparams]]
        self.aoclist.append(['delete', self.uocparams])
    
    def interact_parse(self):
        "交互性命令分析"
        print 'in uocdelete interact_parse'
        rid = None
        while not rid:
            st = self.get_input('待删除记录ID')
            if not st:
                return None
            if st == 'default':
                continue
            else:
                rid = uocbase.field_validate(st, 'int')
                if rid:
                    break
                else:
                    print '格式输入错误'
        self.uocparams = [rid]
        
        yn = None
        while not yn:
            st = self.get_input('确定要删除该条记录么？(y/n)')
            if not st:
                return None
            if st == 'default':
                break
            else:
                yn = uocbase.field_validate(st, 'yn')
                if yn:
                    break
                else:
                    print '格式输入错误'
        if yn == 'y':
            print '确定删除操作'
            self.aoclist.append(['delete', self.uocparams])
        else:
            print '取消删除操作'
        
